package Aleehot100;

/**
 * ClassName: c063
 * Package: Aleehot100
 * Description:35. 搜索插入位置
 *
 * @Author BCXJ
 * @Create 2025/8/14 08:27
 * @Version 1.0
 * @Since 1.0
 */
public class c063 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,6,7};
        System.out.println(searchInsert(arr, 5));
    }
    public static int searchInsert(int[] nums, int target) {
        int l = 0, r = nums.length - 1, mid = 0;
        while(l <= r) {
            mid = l + ((r - l) >> 1);
            if(nums[mid] == target) {
                return mid;
            } else if(nums[mid] > target) {
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }
}
